package com.company.cloud.userdata.modules.app.service.impl;

import com.company.cloud.common.bean.BaseClientResult;
import com.company.cloud.common.constant.BaseReturnEnum;
import com.company.cloud.common.utils.CheckUtils;
import com.company.cloud.crm.modules.api.request.CustomerNumStatisticsRequest;
import com.company.cloud.crm.modules.api.response.CustomerNumStatisticsResponse;
import com.company.cloud.crm.modules.api.service.CrmRemoteService;
import com.company.cloud.userdata.modules.app.controller.req.BrokerDataStatisticsModel;
import com.company.cloud.userdata.modules.app.controller.req.UserDataStatisticsModel;
import com.company.cloud.userdata.modules.app.service.UserDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.security.KeyStore;

@Service
public class UserDataServiceImpl implements UserDataService {

    @Autowired
    private CrmRemoteService crmRemoteService;

    @Override
    public UserDataStatisticsModel getUserDataStatistics(Integer userId) {
        return new UserDataStatisticsModel();
    }

    @Override
    public BrokerDataStatisticsModel getBrokerDataStatistics(Integer userId) {
        BrokerDataStatisticsModel data = new BrokerDataStatisticsModel();
        //todo 并发访问
        data.setVisitNum(this.customerNumStatistics(userId));
        return data;
    }

    /***/
    private Integer customerNumStatistics(Integer userId){
        CustomerNumStatisticsRequest custReq = new CustomerNumStatisticsRequest();
        custReq.setUserId(userId);
        BaseClientResult<CustomerNumStatisticsResponse> custResp = crmRemoteService.customerNumStatistics(custReq);
        if(CheckUtils.hasClientResult(custResp)&&custResp.getData()!=null){
            return custResp.getData().getNum();
        } else {
            return 0;
        }
    }

}
